package me.samlss.lighter_demo.slice;

import me.samlss.lighter_demo.ResourceTable;
import me.samlss.lighter_demo.dialog.CustomDialog;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
/**
 * @author: zhu_zhonglin
 * @time: 2021/4/25
 */
public class DialogAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private DependentLayout dialog_root;
    private Text title_tv;
    private Image back_iv;
    private Button button;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_dialog);
        initView();
    }

    private void initView() {
        dialog_root = (DependentLayout) findComponentById(ResourceTable.Id_dialog_root);
        title_tv = (Text) findComponentById(ResourceTable.Id_title_tv);
        title_tv.setText("Dialog");
        back_iv = (Image) findComponentById(ResourceTable.Id_back_iv);
        back_iv.setClickedListener(component -> getAbility().terminateAbility());
        button = (Button) findComponentById(ResourceTable.Id_button);
        button.setClickedListener(this);

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_button:
                new CustomDialog(getContext()).show();
                break;
        }
    }
}
